﻿using System;
using ReactiveGraph.Core;

namespace ReactiveGraph.Object
{
    public class NodeFactories
    {
        private readonly Func<string, Type, IReactiveNode> _createNamedNodeForType;
        private readonly Func<Type, IReactiveNode> _createNodeForType;
        private readonly Func<string, Type, IProperty> _createProperty;
        private readonly Func<IReactiveNode, string> _createNameForNode;

        public NodeFactories(
            Func<string, Type, IReactiveNode> createNamedNodeForType,
            Func<Type, IReactiveNode> createNodeForType,
            Func<string, Type, IProperty> createProperty,
            Func<IReactiveNode, string> createNameForNode
            )
        {
            _createNamedNodeForType = createNamedNodeForType;
            _createNodeForType = createNodeForType;
            _createProperty = createProperty;
            _createNameForNode = createNameForNode;
        }


        public IReactiveNode CreateNamedNodeForType(string name, Type nodeType)
        {
            return _createNamedNodeForType(name, nodeType);
        }

        public IReactiveNode CreateNodeForType(Type nodeType)
        {
            return _createNodeForType(nodeType);
        }

        public IProperty CreateProperty(string name, Type propertyType)
        {
            return _createProperty(name, propertyType);
        }

        public string GetNameForNode(IReactiveNode node)
        {
            return _createNameForNode(node);
        }
    }

    public class Context
    {
        public Context(NodeFactories factories)
        {
            Factories = factories;
        }

        public NodeFactories Factories { get; private set; }
    }
}
